/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.connor.bank.Controller;

import com.connor.bank.Control;
import com.connor.bank.Resource.ResourceHandler;
import com.connor.bank.Resource.Session;
import com.connor.bank.View;
import java.util.Map;

/**
 *
 * @author raytang
 */
public class UserChoiceControl extends Control{

    
    @Override 
    public void actionWith(String userCommand, View view) {
        String role = (String) Session.getAttributeValue("role");
        if(role.equals("admin")){
            Map<String, String> functions = ResourceHandler.getAllValue("adminFunction");
            if(functions.containsValue(userCommand))
                mc.actionWith(userCommand, this, view);
            else
                mc.actionWith("userChoiceError", this, view);
        }
        else if(role.equals("user")){
            Map<String, String> functions = ResourceHandler.getAllValue("userFunction");
            if(functions.containsValue(userCommand))
                mc.actionWith(userCommand, this, view);
            else
                mc.actionWith("userChoiceError", this, view);
        }
    }
    
}
